/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package scheduler;

import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author Musikero
 */
public class extractStudId {
    public static void main(String[] args){
        try{
            String studentId;
            String password;
            BufferedWriter write = new BufferedWriter(new FileWriter( new File("StudLogin.txt")));

            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            String conStr = "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=D:\\DatabaseUpdate.accdb";
            //edit the database location above: d:/student.accdb
            Connection con = DriverManager.getConnection(conStr);
            System.out.println("Connected");

            String selectStatement = "SELECT * FROM student WHERE CLASSCODE='9572'";
            //Edit the statement above
            Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
            ResultSet result = stmt.executeQuery(selectStatement);
            Ciphering ciphering = new Ciphering();
            
            int pw = 1;
            write.write(".");
            write.newLine();
                    
            result.beforeFirst();
            while(result.next()){
                studentId = result.getString(1);
                password = ciphering.encrypt(studentId,4);
                System.out.println(password);
                //write.write(studentId + " " + password);
                write.write(studentId + " " + ciphering.encrypt(password,4));
                write.newLine(); 
                pw++;
            }
            write.close(); 
        }
        catch(IOException | ClassNotFoundException | SQLException exceptionHandler){
            System.out.print("An Error Occured");
        }   
    }
}